home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / util / json.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  108 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import simplejson
  5.  
  6. def serialize(thing):
  7.     if type(thing) is dict:
  8.         return dict((lambda .0: for a, b in .0:
  9. (serialize(a), serialize(b)))(thing.iteritems()))
  10.     elif isinstance(thing, str):
  11.         return '__str__' + thing
  12.     elif isinstance(thing, unicode):
  13.         return '__unicode__' + thing
  14.     elif isinstance(thing, bool):
  15.         if thing:
  16.             return '__True__'
  17.         else:
  18.             return '__False__'
  19.     elif isinstance(thing, (int, long)):
  20.         return '__int__' + str(thing)
  21.     elif isinstance(thing, float):
  22.         return '__float__' + repr(thing)
  23.     elif isinstance(thing, type(None)):
  24.         return '__None__'
  25.     elif type(thing) is tuple:
  26.         return {
  27.             '__tuple__': list((lambda .0: for foo in .0:
  28. serialize(foo))(thing)) }
  29.     elif type(thing) is list:
  30.         return list((lambda .0: for foo in .0:
  31. serialize(foo))(thing))
  32.     elif type(thing) is set:
  33.         []['__set__'] = [ serialize(foo) for foo in sorted(thing) ]
  34.         return []
  35.     elif type(thing) is frozenset:
  36.         []['__frozenset__'] = [ serialize(foo) for foo in sorted(thing) ]
  37.         return []
  38.     
  39.  
  40.  
  41. def unserialize(thing):
  42.     if type(thing) is unicode:
  43.         if thing.startswith('__str__'):
  44.             return str(thing[7:])
  45.         
  46.         if thing.startswith('__unicode__'):
  47.             return unicode(thing[11:])
  48.         
  49.         if thing.startswith('__int__'):
  50.             return int(thing[7:])
  51.         
  52.         if thing.startswith('__float__'):
  53.             return float(thing[9:])
  54.         
  55.         if thing == '__None__':
  56.             return None
  57.         
  58.         if thing == '__True__':
  59.             return True
  60.         
  61.         if thing == '__False__':
  62.             return False
  63.         
  64.         return thing
  65.     
  66.     if type(thing) is dict:
  67.         return dict((lambda .0: for foo, bar in .0:
  68. (unserialize(foo), unserialize(bar)))(thing.iteritems()))
  69.     elif type(thing) is set:
  70.         return set((lambda .0: for foo in .0:
  71. unserialize(foo))(thing))
  72.     elif type(thing) is frozenset:
  73.         return frozenset((lambda .0: for foo in .0:
  74. unserialize(foo))(thing))
  75.     elif type(thing) is tuple:
  76.         return tuple((lambda .0: for foo in .0:
  77. unserialize(foo))(thing))
  78.     elif type(thing) is list:
  79.         return list((lambda .0: for foo in .0:
  80. unserialize(foo))(thing))
  81.     
  82.  
  83.  
  84. def untupleset(obj):
  85.     if '__tuple__' in obj:
  86.         return tuple(obj['__tuple__'])
  87.     elif '__set__' in obj:
  88.         return set(obj['__set__'])
  89.     elif '__frozenset__' in obj:
  90.         return frozenset(obj['__frozenset__'])
  91.     
  92.     return obj
  93.  
  94.  
  95. def pydumps(obj):
  96.     return simplejson.dumps(serialize(obj), sort_keys = True, separators = (',', ':'))
  97.  
  98.  
  99. def pyloads(obj):
  100.     return unserialize(simplejson.loads(obj, object_hook = untupleset))
  101.  
  102. __all__ = [
  103.     'pydumps',
  104.     'pyloads']
  105. if __name__ == '__main__':
  106.     pass
  107.  
  108.